home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS Toolkit
/
BBS Toolkit.iso
/
doors_2
/
ringchk1.zip
/
RINGCHEK.C
next >
Wrap
C/C++ Source or Header
|
1992-08-17
|
3KB
|
87 lines
/* This program waits 7 seconds for a RING from the modem and exits with */
/* an errorlevel of 1 if gets one within that time. Also handles KB:. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <process.h>
#include <conio.h>
#include <time.h>
#include <dos.h> /* Dos-specific functions are used to get date/time. */
#include "common.h"
#include "modem.h" /* Routines for accessing the modem. */
/*---------------------------- The program! ----------------------------*/
int main(int argc, char *argv[])
{
char arg_port[64],arg_baud[64];
time_t ending_time;
int the_char;
printf("RINGCHEK -- Alton Moore -- Fidonet 1:397/5264, WWIVnet 1@1042\n");
if (argc != 3)
{
printf("?Illegal number of arguments.%c\n",BELL_string[0]);
printf("\nSpecify com port, then baud rate on the command line, eg:\n\n");
printf(" RINGCHEK 2 19200\n\n");
printf("Error levels returned: 0 -- No RING; no keyboard abort (SUCCESS)\n");
printf(" 1 -- RING was detected from modem\n");
printf(" 2 -- Key pressed to abort callout\n");
printf(" 9 -- Parameter or program's error\n");
printf("\nExiting with errorlevel 9....\n");
return(9);
}
strcpy(arg_port,argv[1]);
strcpy(arg_baud,argv[2]);
modem_port = atoi(arg_port);
modem_speed = atoi(arg_baud);
if (initSerial(modem_port,modem_speed,modem_parity,modem_bits,modem_stopbits))
{
printf("?Couldn't initialize serial port; exiting with errorlevel 9!\n");
return(9);
}
printf("Waiting 7 seconds for RING from modem. Hit space bar to\n");
printf("hurry up or press any other key to abort next operation.\n");
trace_start("RING");
ending_time = time(NULL) + 7; /* Wait for 7 seconds.... */
while (time(NULL) < ending_time)
{
if (kbhit())
{
deinitSerial(0);
trace_stop_all();
if (getch() == ' ')
{
printf("Quitting and exiting with errorlevel 0!\n");
return(0);
}
else
{
printf("Key pressed; aborting and exiting with errorlevel 2!\n");
return(2);
}
}
the_char = port_in(); /* Anything from the modem? */
if (the_char != -1)
trace_process_received_character(the_char);
if (trace_fired("RING"))
{
printf("RING detected from modem; exiting with errorlevel 1!\n");
trace_stop_all();
trash_modem_output(modem_port,0);
deinitSerial(0);
return(1);
}
}
printf("Nothing detected; exiting with errorlevel 0.\n");
trace_stop_all();
deinitSerial(0);
return(0);
}